﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
     
    </div>

    <div class="table-page-search-wrapper"> 
      <div class="table-page-search-wrapper" style="text-align: right;">
      <a-input v-model="queryParam.keyword"  style="width: 20%" placeholder="请输入设备编号" />

      <a-button
        type="primary"
        icon="search"
        style="margin-left: 8px"
        @click="
          () => {
            this.pagination.current = 1
            this.getDataList()
          }
        "
      >
        搜索
      </a-button>

      <a-button icon="search" style="margin-left: 8px" @click="() =>{ 
        if(this.divistrue){ 
          this.divistrue = false
        }else{
          this.divistrue = true 
        }
        
        }">高级搜索</a-button>
      <a-button style="margin-left: 8px" icon="redo" @click="() => (queryParam = {})">重置</a-button>
      <a-button type="primary" style="margin-left: 8px;" v-if="hasPerm('equipment.Add')" icon="plus" @click="hanldleAdd()">新建</a-button>
      <a-button
        v-if="hasPerm('equipment.Delete')"
        type="danger"
        style="margin-left: 8px"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
        >删除</a-button
      >
      <a-button type="primary" icon="redo" style="margin-left: 8px" @click="getDataList()">刷新</a-button>
    </div>

    </div>

    <a-drawer
    :width="500"
    title="高级筛选"
    placement="top"
    :visible="divistrue"
    @close="onClose"
  >
    
    <a-row>
      <a-col :span="8">设备编号&emsp;<a-input v-model="queryParam.keyword" placeholder="请输入车牌号" style="width:80%"></a-input></a-col>
        <a-col :span="8">设备主姓名&emsp;<a-input v-model="queryParam.EmpName" style="width:80%" placeholder="请输入车主姓名"></a-input></a-col>
       
        <a-col :span="8">品牌及型号&emsp;<a-input v-model="queryParam.CarBrandModel" style="width:80%" placeholder="请输入品牌及型号"></a-input></a-col>
    </a-row>
    <a-row style="margin-top:10px">
        <a-col :span="8">状&emsp;&emsp;态&emsp;
          <a-select v-model="queryParam.Status" placeholder="请选择审核状态" style="width:80%">
            <a-select-option value="">全部数据</a-select-option>
            <a-select-option value="1">已审核</a-select-option>
            <a-select-option value="0">未审核</a-select-option>
          </a-select>
        </a-col>
        
    </a-row>
    
      <div style="text-align:right;margin-top:30px">
      <a-button  @click="onClose" icon="close">关闭</a-button>
      <a-button type="primary" style="margin-left:8px" icon="search" @click="() => {
            this.pagination.current = 1
            this.getDataList()
            this.divistrue=  false
          }">查询</a-button>
      </div>
  
  </a-drawer>

    <a-table
      ref="table"
      :columns="columns"
      :rowKey="(row) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >
      <template slot="Status" slot-scope="text">
        <span v-if="text == '1'"><a-tag color="green">已审核</a-tag></span>
        <span v-if="text == '0'"><a-tag color="red">未审核</a-tag></span>
      </template>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.Id)" v-if="hasPerm('equipment.Edit')"
            ><a-tag color="blue"><a-icon type="form" /> 编辑</a-tag></a
          >
          <a-divider type="vertical" />
          <!-- <a @click="handleDelete([record.Id])">删除</a> -->
          <a-popconfirm
            title="确定删除吗？"
            v-if="hasPerm('equipment.Delete')"
            ok-text="确定"
            cancel-text="取消"
            @confirm="handleDelete([record.Id])"
            @cancel="cancel"
          >
            <a href="#">删除</a>
          </a-popconfirm>
          <a-divider type="vertical" v-if="record.Status == 0" />
          <a @click="handleCheck(record.Id)" v-if="record.Status == 0">审核</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'

const columns = [
  { title: '设备编号', dataIndex: 'DeviceNo', width: '10%' },
  // { title: '品牌型号', dataIndex: 'DeviceBrandModel', width: '10%' },
  // { title: '所有人id', dataIndex: 'EmpId', width: '10%' },
  { title: '持有人', dataIndex: 'EmpName', width: '10%' },
  { title: '租金', dataIndex: 'Rental', width: '10%' },
  { title: '入驻时间', dataIndex: 'CreateTime', width: '20%' },
  { title: '状态', dataIndex: 'Status', width: '10%', scopedSlots: { customRender: 'Status' } },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } },
]

export default {
  components: {
    EditForm,
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      divistrue:false,
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: [],
    }
  },
  methods: {
    onClose(){
      this.divistrue = false
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_Leasesystem_equipment/leasesystem_equipment/GetHeightSearch', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data.Result.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Data.Result.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.editForm.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleCheck(id) {
      this.$refs.editForm.openForm(id)
    },
    handleDelete(ids) {
      var thisObj = this

      return new Promise((resolve, reject) => {
        thisObj.$http.post('/Base_Leasesystem_equipment/leasesystem_equipment/DeleteData', ids).then((resJson) => {
          resolve()

          if (resJson.Success) {
            thisObj.$message.success('操作成功!')

            thisObj.getDataList()
          } else {
            thisObj.$message.error(resJson.Msg)
          }
        })
      })
    },
    cancel(e) {
      this.$message.error('已取消删除')
    },
  },
}
</script>

<style>
.ant-table-thead > tr > th
{
  font-weight: 600;
  color: #333333;
}
</style>